package edu.cs335pl.questionnaire;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;
import edu.cs335pl.questionnaire.util.ReportDemo;
import org.junit.Test;

import java.util.Calendar;
import java.util.HashMap;

public class test {
    @Test
    public void contextLoads(){
        HashMap<String,Object> map = new HashMap<>();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.SECOND,200);
        String token = JWT.create()
                .withHeader(map)
                .withClaim("id",21)
                .withClaim("company","IBM")
                .withExpiresAt(calendar.getTime())
                .sign(Algorithm.HMAC256("dhfosanoisr"));
        System.out.println(token);
    }

    @Test
    public void test(){
        JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256("dhfosanoisr")).build();
        DecodedJWT verif = jwtVerifier.verify("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb21wYW55IjoiSUJNIiwiaWQiOjIxLCJleHAiOjE2MjEwNDc4NjF9.KzMhkmwG-gNXBquuTDazrqCoC_mBe5vAWXGiTX9dXGs\n");
        System.out.println(verif.getClaim("id").asInt());
        System.out.println(verif.getClaim("company").asString());
    }

    @Test
    public void testGenerate(){
        ReportDemo.analysis(4,300);
    }
}
